package org.healthy.controller;

import org.healthy.controller.base.BaseController;
import org.healthy.model.page.Pagination;
import org.healthy.model.user.Paper;
import org.healthy.model.user.User;
import org.healthy.service.IPaperService;
import org.healthy.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 17/10/11.
 */
@Controller
@RequestMapping("/api")
public class PaperController extends BaseController {
    @Resource(name = "paperService")
    private IPaperService paperService;

    /**
     * 根据paperid获取Paper
     *
     * @param id
     */

    @ResponseBody
    @RequestMapping(value = "/v1/paper/getpaper", method = RequestMethod.POST)
    public String getPaper(@RequestParam String id) {
        Paper v = paperService.getPaperByid(id);
        return response(v);
    }

    /**
     * 搜索试卷
     *
     * @param paper
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/v1/paper/queryPaper", method = RequestMethod.POST)
    public String searchPapers(@RequestBody Paper paper) {
        List<Paper> vs = paperService.searchPaper(paper);
        return response(vs);
    }

    /**
     * 收藏试卷
     *
     * @param uid
     * @param pid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/v1/paper/collectPaper", method = RequestMethod.POST)
    public String collectPaper(@RequestParam Long uid, @RequestParam String pid
    ) {
        paperService.collectPaper(uid, pid);
        return response(null);
    }

    /**
     * 获取我收藏的试卷
     *
     * @param uid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/v1/paper/myCollectPapers", method = RequestMethod.POST)
    public String getMyCollectPapers(@RequestParam Long uid, @RequestParam Integer pageno, @RequestParam Integer pagesize) {
        Pagination<Paper> page = new Pagination<Paper>(pageno, pagesize);
        List<Paper> papers = paperService.getCollectPaper(uid, page);
        page.setV(papers);
        return response(papers);
    }

    /**
     * 获取推荐的试卷
     *
     * @param uid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/v1/paper/rmdPaper", method = RequestMethod.POST)
    public String getRmdPapers(@RequestParam Long uid) {
        List<Paper> papsers = paperService.getRmdPapers(uid);
        return "";

    }

    /**
     * 获取试卷标题
     *
     * @param pid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/v1/paper/getPaperTitle", method = RequestMethod.POST)

    public String getPaperTitle(@RequestParam String pid) {
        return paperService.getPaperTitle(pid);
    }


}
